package com.sm.controller;

import com.sm.entity.Notice;
import com.sm.entity.ResultMap;
import com.sm.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.method.P;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/admin/notice")
public class NoticeController {

    @Autowired
    ResultMap resultMap;
    @Autowired
    NoticeService noticeService;


    @RequestMapping("/notice")
    public String notice()throws Exception{
        return "admin/notice/notice";
    }

    @ResponseBody
    @RequestMapping(value = {"/notice.do","/noticesearch"})
    public ResultMap noticeDo()throws Exception{
        List<Notice> notices = noticeService.findAllNotice();
        resultMap.setResult("notices",notices);
        return resultMap;
    }

    @RequestMapping("/noticeadd")
    public String noticeAdd()throws Exception{
        return "admin/notice/noticeadd";
    }

    @ResponseBody
    @RequestMapping("/noticeadd.do")
    public ResultMap noticeAddDo(Notice notice)throws Exception{
        noticeService.addNotice(notice);
        resultMap.setMessage("添加成功");
        return resultMap;
    }

    @RequestMapping("/noticeadmin")
    public String noticeAdmin()throws Exception{
        return "admin/notice/noticeadmin";
    }


    @RequestMapping("/noticemodify/{id}")
    public String noticeModify(@PathVariable("id")Integer nid)throws Exception{
        return "admin/notice/noticemodify";
    }

    @ResponseBody
    @RequestMapping("/noticemodify.do")
    public ResultMap noticeModifyDo()throws Exception{
//        noticeService.updateNotice(notice);
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("/noticedelete/{id}")
    public ResultMap noticeDelete(@PathVariable("id")Integer nid)throws Exception{
        return resultMap;
    }

    @ResponseBody
    @RequestMapping("/noticeone/{id}")
    public ResultMap noticeOne(@PathVariable("id")Integer nid)throws Exception{
        Notice notice = noticeService.findNoticeByNid(nid);
        resultMap.setResult("notice",notice);
        return resultMap;
    }
}
